home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Jul / DI9807AM / tapiu_1.pas < prev   
Pascal/Delphi Source File  |  1997-12-19  |  16KB  |  416 lines

  1. { Listing 1 }
  2.   
  3. unit TAPIU_1;
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  9.   StdCtrls, ExtCtrls, Mask;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     Memo: TMemo;
  14.     Panel1: TPanel;
  15.     ePhoneNum: TMaskEdit;
  16.     btnDial: TButton;
  17.     Label1: TLabel;
  18.     btnHangup: TButton;
  19.     rbDefault: TRadioButton;
  20.     rbCallManager: TRadioButton;
  21.     procedure btnDialClick(Sender: TObject);
  22.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure btnHangupClick(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.     function  TapiInitialize: boolean;
  28.     procedure CreateCallManager;
  29.   public
  30.     { Public declarations }
  31.     { Because ShutdownCallManager is called from the CallBack function,
  32.       ShutdownCallManager must be declared public }
  33.     function  ShutdownCallManager: boolean;
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. uses
  44.   Tapi;
  45.  
  46. var
  47.     FLineApp: HLINEAPP;
  48.     FNumDevs,
  49.     FVersion: Integer;
  50.     FExt: TLINEEXTENSIONID;
  51.     FLine: HLINE;
  52.     FLineCallParams: TLineCallParams;
  53.     FLineOpen: boolean;
  54.     FHCall: HCALL;
  55.     FCountryCode: integer;
  56.     FDev: integer; //value of device ID to initialize, 0..NumDevs }
  57.  
  58. const
  59.   HiVer = $00020000;  // Highest API version wanted (2.0) - Windows NT
  60.   LoVer = $00010004;  // Lowest API version accepted (1.4) - Windows 95
  61.  
  62. procedure LineCallBack(hDevice, dwMessage, dwInstance, dwParam1, dwParam2,
  63.   dwParam3 : DWORD); stdcall; // handles messages from the line
  64. begin
  65.   with Form1, Memo.Lines do begin
  66.     case dwMessage of
  67.       LINE_CALLSTATE: begin //reports asynchronous responses
  68.        case dwParam1 of
  69.           LINECALLSTATE_IDLE:
  70.             begin
  71.             Add('LCB (LINE_CALLSTATE): ' +
  72.                 'The call is idle - no call actually exists.');
  73.             ShutdownCallManager;
  74.             end;
  75.           LINECALLSTATE_OFFERING:
  76.              Add('LCB (LINE_CALLSTATE): ' +
  77.                  'The call is being offered to the station.');
  78.           LINECALLSTATE_ACCEPTED:
  79.              Add('LCB (LINE_CALLSTATE): ' +
  80.                  'The call was offering and has been accepted.');
  81.           LINECALLSTATE_DIALTONE:
  82.              Add('LCB (LINE_CALLSTATE): The call is receiving a dial tone.');
  83.           LINECALLSTATE_DIALING:
  84.              Add('LCB (LINE_CALLSTATE): Dialing ' + Form1.ePhoneNum.Text);
  85.           LINECALLSTATE_RINGBACK:
  86.              Add('LCB (LINE_CALLSTATE): The call is receiving ringback.');
  87.           LINECALLSTATE_BUSY: begin // note, difficult to detect
  88.              case dwParam2 of
  89.                 LINEBUSYMODE_STATION:
  90.                    Add('LCB (LINE_CALLSTATE): ' +
  91.                        'Busy signal; called party''s station is busy.');
  92.                 LINEBUSYMODE_TRUNK:
  93.                    Add('LCB (LINE_CALLSTATE): ' +
  94.                        'Busy signal; trunk or circuit is busy.');
  95.                 LINEBUSYMODE_UNKNOWN:
  96.                    Add('LCB (LINE_CALLSTATE): ' +
  97.                        'Busy signal; specific mode is currently unkown');
  98.                 LINEBUSYMODE_UNAVAIL:
  99.                    Add('LCB (LINE_CALLSTATE): ' +
  100.                        'Busy signal; specific mode is unavailable');
  101.              else
  102.                 Add('LCB (LINE_CALLSTATE): ' +
  103.                     'The call is receiving an unidentifiable busy tone.');
  104.              end;
  105.              ShutdownCallManager;
  106.           end;
  107.           LINECALLSTATE_SPECIALINFO:
  108.              Add('LCB (LINE_CALLSTATE): ' +
  109.                  'Special information is sent by the network.');
  110.           LINECALLSTATE_CONNECTED:
  111.              Add('LCB (LINE_CALLSTATE): ' +
  112.                  'The call has been established and the connection is made.');
  113.           LINECALLSTATE_PROCEEDING:
  114.              Add('LCB (LINE_CALLSTATE): ' +
  115.                  'Dialing has completed and the call is proceeding.');
  116.           LINECALLSTATE_ONHOLD:
  117.              Add('LCB (LINE_CALLSTATE): The call is on hold by the switch.');
  118.           LINECALLSTATE_CONFERENCED:
  119.              Add('LCB (LINE_CALLSTATE): The call is currently ' +
  120.                  'a member of a multi-party conference call.');
  121.           LINECALLSTATE_ONHOLDPENDCONF:
  122.              Add('LCB (LINE_CALLSTATE): The call is currently ' +
  123.                  'on hold while it is being added to a conference.');
  124.           LINECALLSTATE_DISCONNECTED: begin
  125.              Add('LCB (LINE_CALLSTATE): The line has been disconnected.');
  126.              case dwParam2 of
  127.                LINEDISCONNECTMODE_NORMAL:
  128.                  Add(#9 + 'This is a "normal" disconnect request.');
  129.                LINEDISCONNECTMODE_UNKNOWN:
  130.                  Add(#9 + 'The reason for the disconnect request is unknown.');
  131.                LINEDISCONNECTMODE_REJECT:
  132.                  Add(#9 + 'The remote user has rejected the call.');
  133.                LINEDISCONNECTMODE_PICKUP:
  134.                  Add(#9 + 'The call was picked up from elsewhere.');
  135.                LINEDISCONNECTMODE_FORWARDED:
  136.                  Add(#9 + 'The call was forwarded by the switch.');
  137.                LINEDISCONNECTMODE_BUSY:
  138.                  Add(#9 + 'The remote user''s station is busy.');
  139.                LINEDISCONNECTMODE_NOANSWER:
  140.                  Add(#9 + 'The remote user''s station does not answer.');
  141.                LINEDISCONNECTMODE_BADADDRESS:
  142.                  Add(#9 + 'The destination address in invalid.');
  143.                LINEDISCONNECTMODE_UNREACHABLE:
  144.                  Add(#9 + 'The remote user could not be reached.');
  145.                LINEDISCONNECTMODE_CONGESTION:
  146.                  Add(#9 + 'The network is congested.');
  147.                LINEDISCONNECTMODE_INCOMPATIBLE:
  148.                  Add(#9+'The remote user''s station equipment is incompatible');
  149.                LINEDISCONNECTMODE_UNAVAIL:
  150.                  Add(#9 + 'The reason for the disconnect is unavailable');
  151.              end;
  152.            end;
  153.            LINECALLSTATE_UNKNOWN:
  154.              Add('LCB (LINE_CALLSTATE): The state of the call is not known.');
  155.            end;
  156.         end;
  157.       LINE_LINEDEVSTATE:
  158.         case dwParam1 of // incomplete list
  159.           LINEDEVSTATE_RINGING:
  160.              Add('LCB (LINE_LINEDEVSTATE): (Ringing) Ring, ring, ring...');
  161.           LINEDEVSTATE_CONNECTED:
  162.              Add('LCB (LINE_LINEDEVSTATE): Connected...');
  163.           LINEDEVSTATE_DISCONNECTED:
  164.              Add('LCB (LINE_LINEDEVSTATE): Disconnected.');
  165.           LINEDEVSTATE_REINIT: // line device has changed or been modified
  166.              if (dwParam2 = 0) then begin
  167.                 Add('LCB (LINE_LINEDEVSTATE): Shutdown required');
  168.                 ShutdownCallManager;
  169.              end;
  170.         end;
  171.       LINE_REPLY:
  172.          if (dwParam2 = 0) then
  173.             Add('LCB (LINE_REPLY): LineMakeCall completed successfully')
  174.          else
  175.             Add('LCB (LINE_REPLY): LineMakeCall failed');
  176.    end;
  177.   end;
  178. end;
  179. //------------------------------------------------------------------------------
  180.  
  181. procedure TForm1.btnDialClick(Sender: TObject);
  182. var
  183.   ErrNo: longint;
  184.   S: string;
  185. begin
  186.   if rbCallManager.Checked then begin
  187.      btnDial.Enabled := false;  // disable the dial button
  188.      btnHangup.Enabled := true; // and enable the hangup button
  189.      CreateCallManager;
  190.   end
  191.   else begin // use default call manager
  192.      { not necessary to disable the buttons, the default call manager
  193.        handles everything }
  194.      ErrNo := TapiRequestMakeCall(
  195.         PChar(ePhoneNum.Text), // the phone number
  196.         '', // application name, optional, could use PChar(Application.Title)
  197.         'Some person', // optional, this is the name of the person being called
  198.         ''); // optional comment
  199.      case ErrNo of
  200.         0: S := 'success!'; // success
  201.         TAPIERR_NOREQUESTRECIPIENT: S := 'TAPIERR_NOREQUESTRECIPIENT';
  202.         TAPIERR_INVALDESTADDRESS: S := 'TAPIERR_INVALDESTADDRESS';
  203.         TAPIERR_REQUESTQUEUEFULL: S := 'TAPIERR_REQUESTQUEUEFULL';
  204.         TAPIERR_INVALPOINTER: S := 'TAPIERR_INVALPOINTER';
  205.      else